<div class="container">
    <h4>Quản lý danh mục</h4>
</div>
<div class="container" style="margin-bottom: -1px;" >
    <div style="margin-top: 10px" >
        <ul class="nav nav-tabs nav-collapse">
            <li class="active">
                <a href="<?= $this->baseUrl ?>cp/catelog.html">Danh sách danh mục</a>
            </li>
        </ul>
    </div>      
</div> 
<div class="container" style="border: 1px solid #ccc; padding-top: 10px;" >
    <div class="form-group ">
        <button type="button" onclick="catelog.add();" class="btn btn-info">
            <i class="glyphicon glyphicon-plus"></i> Thêm danh mục
        </button>
    </div>
    <p class="clearfix" ></p>
    <div style="margin-top: 10px;">
        <h5 class="pull-left alert alert-success" style="padding: 10px; width: 33%;" >
            Tìm thấy tổng số 
            <span style="color: tomato; font-weight: bolder"><?= $dataPage->dataCount ?></span> 
            danh mục trong 
            <span style="color: tomato; font-weight: bolder"><?= $dataPage->pageCount ?></span> trang.
        </h5>
        <div class="btn-toolbar pull-right" style="padding: 15px 0px;">
            <?= $this->loadView('/widget/page'); ?>
        </div>
    </div>
    <p class="clearfix" ></p>
    <table  class="table table-striped table-bordered table-responsive" style="margin-bottom: 10px;" >
        <thead>
            <tr class="success" >
                <th class="text-center">Mã</th>
                <th class="text-center">Tên danh mục</th>
                <th class="text-center">Kiểu danh mục</th>                             
                <th class="text-center">Danh mục cha</th>                             
                <th class="text-center">
                    Trạng thái
                    <i class="glyphicon glyphicon-edit pull-right"></i>
                </th>   
                <th class="text-center">Chức năng</th>                             
            </tr>
        </thead>
        <tbody>
            <?php $arrItem = array(); ?>
            <?php foreach ($dataPage->data as $item) { ?>
                <?php
                if ($item->parentId == '0') {
                    $arrItem[] = $item->id;
                    ?>
                    <tr>
                        <td class="text-center" style="vertical-align: middle" ><?= @$item->id ?></td>
                        <td  style="vertical-align: middle" > -- <?= @$item->name ?></td>
                        <td class="text-center" style="vertical-align: middle" >
                            <?php
                            switch ($item->type) {
                                case application\entity\enu\CatelogType::APP: echo "Ứng dụng";
                                    break;
                                case application\entity\enu\CatelogType::GAME: echo "Game";
                                    break;
                                case application\entity\enu\CatelogType::IMAGE: echo "Hình ảnh";
                                    break;
                                case application\entity\enu\CatelogType::NEWS: echo "Tin tức";
                                    break;
                                case application\entity\enu\CatelogType::STORY: echo "Truyện";
                                    break;

                                default:
                                    break;
                            }
                            ?>
                        </td>
                        <td class="text-center" style="vertical-align: middle" >Danh mục gốc</td>
                        <td class="text-center" style="vertical-align: middle" for="active" ref="<?= @$item->id ?>" >
                            <?= @$item->active ? '<label class="label label-success">Hoạt động</label>' : '<label class="label label-danger">Tạm khóa</label>' ?>
                            <i style="cursor: pointer" onclick="catelog.changeActive('<?= @$item->id ?>');" class="glyphicon glyphicon-<?= @$item->active ? 'check' : 'unchecked' ?> pull-right"></i>
                        </td>
                        <td class="text-center" style="vertical-align: middle" >
                            <div class="btn-group">
                                <button onclick="catelog.edit('<?= @$item->id ?>');" class="btn btn-info" type="button" >
                                    <i class="glyphicon glyphicon-edit"></i> 
                                    Sửa
                                </button>
                                <button onclick="catelog.del('<?= @$item->id ?>');" class="btn btn-danger" type="button" >
                                    <i class="glyphicon glyphicon-remove"></i> 
                                    Xóa
                                </button>
                            </div>
                        </td>
                    </tr>

                    <?php foreach ($dataPage->data as $subitem) { ?>
                        <?php
                        if ($subitem->parentId == $item->id) {
                            $arrItem[] = $subitem->id;
                            ?>
                            <tr>
                                <td class="text-center" style="vertical-align: middle" ><?= @$subitem->id ?></td>
                                <td style="vertical-align: middle" > ---- <?= @$subitem->name ?></td>
                                <td class="text-center" style="vertical-align: middle" >
                                    <?php
                                    switch ($item->type) {
                                        case application\entity\enu\CatelogType::APP: echo "Ứng dụng";
                                            break;
                                        case application\entity\enu\CatelogType::GAME: echo "Game";
                                            break;
                                        case application\entity\enu\CatelogType::IMAGE: echo "Hình ảnh";
                                            break;
                                        case application\entity\enu\CatelogType::NEWS: echo "Tin tức";
                                            break;
                                        case application\entity\enu\CatelogType::STORY: echo "Truyện";
                                            break;

                                        default:
                                            break;
                                    }
                                    ?>
                                </td>
                                <td class="text-center" style="vertical-align: middle" ><?= @$item->name ?></td>
                                <td class="text-center" style="vertical-align: middle" for="active" ref="<?= @$subitem->id ?>" >
                                    <?= @$subitem->active ? '<label class="label label-success">Hoạt động</label>' : '<label class="label label-danger">Tạm khóa</label>' ?>
                                    <i style="cursor: pointer" onclick="catelog.changeActive('<?= @$subitem->id ?>');" class="glyphicon glyphicon-<?= @$item->active ? 'check' : 'unchecked' ?> pull-right"></i>
                                </td>
                                <td class="text-center" style="vertical-align: middle" >
                                    <div class="btn-group">
                                        <button onclick="catelog.edit('<?= @$subitem->id ?>');" class="btn btn-info" type="button" >
                                            <i class="glyphicon glyphicon-edit"></i> 
                                            Sửa
                                        </button>
                                        <button onclick="catelog.changeActive('<?= @$subitem->id ?>');" class="btn btn-danger" type="button" >
                                            <i class="glyphicon glyphicon-remove"></i> 
                                            Xóa
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        <?php } ?>
                    <?php } ?>

                <?php } ?>
            <?php } ?>
            <?php foreach ($dataPage->data as $item) { ?>
                <?php
                if (!in_array($item->id, $arrItem)) {
                    $arrItem[] = $item->id;
                    ?>
                    <tr>
                        <td class="text-center" style="vertical-align: middle" ><?= @$item->id ?></td>
                        <td  style="vertical-align: middle" > -- <?= @$item->name ?></td>
                        <td class="text-center" style="vertical-align: middle" >
                            <?php
                            switch ($item->type) {
                                case application\entity\enu\CatelogType::APP: echo "Ứng dụng";
                                    break;
                                case application\entity\enu\CatelogType::GAME: echo "Game";
                                    break;
                                case application\entity\enu\CatelogType::IMAGE: echo "Hình ảnh";
                                    break;
                                case application\entity\enu\CatelogType::NEWS: echo "Tin tức";
                                    break;
                                case application\entity\enu\CatelogType::STORY: echo "Truyện";
                                    break;

                                default:
                                    break;
                            }
                            ?>
                        </td>
                        <td class="text-center" style="vertical-align: middle" ><?= @$item->parentId ?> (đã bị xóa)</td>
                        <td class="text-center" style="vertical-align: middle" for="active" ref="<?= @$item->id ?>" >
                            <?= @$item->active ? '<label class="label label-success">Hoạt động</label>' : '<label class="label label-danger">Tạm khóa</label>' ?>
                            <i style="cursor: pointer" onclick="catelog.changeActive('<?= @$item->id ?>');" class="glyphicon glyphicon-<?= @$item->active ? 'check' : 'unchecked' ?> pull-right"></i>
                        </td>
                        <td class="text-center" style="vertical-align: middle" >
                            <div class="btn-group">
                                <button onclick="catelog.edit('<?= @$item->id ?>');" class="btn btn-info" type="button" >
                                    <i class="glyphicon glyphicon-edit"></i> 
                                    Sửa
                                </button>
                                <button onclick="catelog.del('<?= @$item->id ?>');" class="btn btn-danger" type="button" >
                                    <i class="glyphicon glyphicon-remove"></i> 
                                    Xóa
                                </button>
                            </div>
                        </td>
                    </tr>

                   

                <?php } ?>
            <?php } ?>
        </tbody>
    </table>
    <p class="clearfix" ></p>
    <div style="margin-top: 10px;">
        <h5 class="pull-left alert alert-success" style="padding: 10px; width: 33%;" >
            Tìm thấy tổng số 
            <span style="color: tomato; font-weight: bolder"><?= $dataPage->dataCount ?></span> 
            danh mục trong 
            <span style="color: tomato; font-weight: bolder"><?= $dataPage->pageCount ?></span> trang.
        </h5>
        <div class="btn-toolbar pull-right" style="padding: 15px 0px;">
            <?= $this->loadView('/widget/page'); ?>
        </div>
    </div>
</div>